// pages/index/refund.js
Page({

  data: {   introduce:'',code:'',list:[],fileList:[],title:'',total:'',file:'',url3:'',sheets:'',dmcopies:'',addtime:''

  },

  
  onLoad: function (options) {
    console.log(options);
    
    this.setData({
      code:options.code,
      total:options.total,
      title:options.title,
      dmcopies:options.dmcopies,
      sheets:options.sheets,
      addtime:options.addtime

    })

  },
    change(e){
      console.log(e);
      if(e.detail.value==''){
        wx.showToast({
          title: '不能为空',
        })
      }else{
        this.setData({
          introduce:e.detail.value
        })
      }
      
    },
    //提交申请
     tijiaoclick(){
       if(this.data.introduce.trim()==''){return wx.showToast({
         title: '请填写退款说明',
         icon:'none'
       })}
       const code=this.data.code
       const content=this.data.introduce
       const uid=wx.getStorageSync('uid')
       const pic=this.data.url3
       const params={code,content,uid,pic}
       wx.request({
         url: 'https://zujieba.com/Api/order/refund_order.html',
         data:params,
         method:'POST',
         success:(res)=>{
           console.log(res);
           wx.showToast({
             title: res.data.tips,
             duration:2000
           })
           wx.navigateBack({
             complete: (res) => {},
           })
           
         }
       })
     },
     afterRead(event) {
      
      const { file } = event.detail;
      console.log(file);
      this.setData({
        file:file.path
      })
      const that=this
        
      
      
      // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
      wx.uploadFile({
        
        url: 'https://zujieba.com/index/upload/upload.html', // 仅为示例，非真实的接口地址
        filePath: file.path,
        name:'file',
        
        success(res) {
          
          const res1=JSON.parse(res.data).name
          const array=[]
          array.push(res1)
          that.setData({
            list:array,
           url3:res1
          })
          
          
          
          console.log(res1);
          const url1="https://zujieba.com/file_index/"+res1
          
          console.log(url1);
          
          const fileList=[]
          const object={}
          object.url=url1
          object.name=2
          object.deletable=true
          
         fileList.push(object) 
          that.setData({ fileList });
        }
        
      });
    },
    deleteclick(){
      
      const list=this.data.fileList
          list.splice(0,1)
         this.setData({
           fileList:list
         })
             
           
      },
  

})